package com.fun;

import java.util.List;

import javax.persistence.Query;

import org.hibernate.Session;

public class ProductDAO {
	Session session = HibernateInitial.getSession();

	public void productsave(Product product) {
		session.beginTransaction();
		try {
			session.save(product);
			session.getTransaction().commit();
		} catch (RuntimeException e) {
			session.getTransaction().rollback();
		}
	}
	public List<Product> findallproduct() {
		session.beginTransaction();
		try {
			List<Product> list = (List<Product>) session.createQuery("from Product").list();
			
			session.getTransaction().commit();
			return list;
		
		} catch (RuntimeException e) {
			session.getTransaction().rollback();
			return null;
		}
		
	}
}
